home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
qtawk
/
apptadd.exp
< prev
next >
Wrap
Text File
|
1990-07-25
|
5KB
|
173 lines
# Utility to Add Repetitive Appoints to Calender
# Input Line of Form:
#
# Start Stop Time Rept. Appointment Comments
# xx/xx/xx xx/xx/xx xx:xx weekly appointment comments --->
# daily
#
BEGIN {
stderr = "stderr";
greg_jul = FALSE;
# the following date formats would be used for U.S. style dates
t0date = sdate(0); # todays date: mm/dd/yy
t1date = sdate(1); # todays date: mm/dd/yyyy
split(t1date,tdate,/\//);
today_jdn = jdn(tdate[3],tdate[1],tdate[2]);
century = tdate[3] / 100;
tdc = /{_d}{1,2}/;
t_pattern = /{tdc}:{tdc}/;
time_pattern = /^{t_pattern}$/;
date_pattern = /{tdc}\/{tdc}\/{tdc}/;
double_date = /({date_pattern}{_w}+){2,2}/;
appt_date = /^{_w}*{date_pattern}{_w}/;
colon_s = /:/;
slash_s = /\//;
# input format
adate = /^{_w}*{double_date}{t_pattern}{_w}+/;
split(t0date,cdate,slash_s);
apptfile = "c:\\appt" ∩ cdate[3] ∩ ".dat";
tmpf = "c:\\$tmp$.tmp";
system("copy " ∩ apptfile ∩ " " ∩ tmpf);
split(stime(2),now,colon_s);
hour = 1;
minute = 2;
}
INITIAL {
if ( FILENAME == "stdin" ) {
print "Add Repeat Appointments.";
print "Input Appointments to Add.";
print "Format: (repeat == weekly/wkly/daily)";
print "start_date stop_date time repeat Appointment";
}
}
adate {
local rc, ii = $1, tac, i;
# index start date - element to stop date
split($2,tac,slash_s);
if ( tac[3] < 100 ) tac[3] += century * 100;
start_date[ii][0] = jdn(tac[3],tac[1],tac[2]);
start_date[ii][1] = $3; # index start date - element to appt. time
rc = strlwr($4) ~~ /w(ee)?kly/ ? 7 : 1;
start_date[ii][2] = rc; # index start date - element to repitition count
$1 = $2 = $3 = $4 = "";
start_date[ii][3] = $0; # index start date - appointment
}
END {
local iline, cline, sd, atim, repc, appt;
local tac, tas, i, c_cnt,c_jdn, i_jdn;
for ( s_date in start_date ) {
split(s_date,tac,slash_s);
if ( tac[3] < 100 ) tac[3] += century * 100;
sd = set_date(tac);
c_jdn = jdn(tac[3],tac[1],tac[2]);
stpd = start_date[s_date][0];
atim = start_date[s_date][1];
repc = start_date[s_date][2];
appt = start_date[s_date][3];
while ( c_cnt = fgetline(tmpf,iline) > 0 ) {
if ( iline ~~ appt_date ) {
split(iline,cline);
print cline[1];
split(cline[1],tas,slash_s);
if ( tas[3] < 100 ) tas[3] += century * 100;
i_jdn = jdn(tas[3],tas[1],tas[2]);
while ( tas[3] == tac[3] && c_jdn <= i_jdn ) {
print(sd,atim,appt);
fprint(apptfile,sd,atim,appt);
if ( !(sd = set_next(tac,stpd,repc)) ) break;
else c_jdn = jdn(tac[3],tac[1],tac[2]);
}
}
fprint(apptfile,iline);
if ( !sd ) break;
}
}
while ( fgetline(tmpf,iline) > 0 ) fprint(apptfile,iline);
system("del " ∩ tmpf);
}
# format date array passed as mm/dd/yy
# date array passed as:
# date[1] == month
# date[2] == day
# date[3] == year
function set_date(date) {
local rdate;
rdate = sprintf("%02u/%02u/%02u",date[1],date[2],(date[3] + 0) % 100);
return rdate;
}
# return date for next appointment or FALSE if past stop date
# tac passes the current date in array and returns new date in array
# tac[1] == month
# tac[2] == day
# tac[3] == year
# function return is new date as string: mm/dd/yy
function set_next(tac,stop_jdn,rept) {
local njdn;
local rdate = FALSE;
njdn = jdn(tac[3],tac[1],tac[2]) + rept;
if ( njdn <= stop_jdn ) {
tac = caln(njdn);
rotate(tac); # get proper order of month/day/year
rdate = set_date(tac);
}
return rdate;
}
# function to convert year/month/day into julian day number
function jdn(year,month,day) {
local yr;
local pfac = 0.6;
local ljdn;
yr = year + (month - 3.0) / 12.0;
ljdn = int(367.0 * yr + pfac) - (2 * int(yr)) + int(yr/4.0)
+ int(day) + 1721117;
if ( !greg_jul ) ljdn += -int(yr/100.0) + int(yr/400.0) + 2;
return ljdn;
}
# function to convert julian dday number to year/month/day
# return array:
# date[1] = year
# date[2] = month
# date[3] = day
function caln(cjdn) {
local n, ic, np, npp, mp;
local yr, mo, day;
local dte; # dte[1] == year, dte[2] == month, dte[3] == day
n = int(cjdn) - 1721119;
ic = int((n - 0.2)/36524.25);
if ( greg_jul ) np = n + 2; else np = n + ic - (ic / 4);
yr = int((np - 0.2)/365.25);
npp = np - int(365.25 * yr);
mp = int((npp - 0.5)/30.6);
day = int(npp + 0.5 - 30.6 * mp);
if ( mp <= 9 ) mo = mp + 3;
else {
yr++;
mo = mp - 9;
}
dte[1] = yr;
dte[2] = mo;
dte[3] = day;
return dte; # return date ARRAY
}